<!DOCTYPE html>
<html lang="zh" style="height: 100%">
<head>
  <title>乐清数据</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
  <div id="container" style="height: 400px"></div>
</div>

  <script type="text/javascript" src="/static/bootstrap/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="/static/js/echarts.min.js"></script>
  <script type="text/javascript" src="/static/js/jquery.js"></script>

  <script type="text/javascript">
    function fillArray(len,value){
        let arr = [];
        for(let i=0;i<len;i++){
          arr[i] = value;
        }
        return arr;
    }
    const app = {};
    function getApp(appid){
      if(!app[appid]) {
        const dom = document.getElementById(appid);
        const myChart = echarts.init(dom, null, {
          renderer: 'canvas',
          useDirtyRect: false
        });
        window.addEventListener('resize', myChart.resize);
        app[appid] = myChart;
      }
      return app[appid];
    }

    $.get('/api/log/logger/daily',function(d){
      let data = d.data;
      let xAxis = [];
      data.sort((a,b)=>{
        return a.date>b.date?1:-1;
      });
      let num = data.length;
      let yUserNum = [];//fillArray(num,0);
      let yIpNum = [];//fillArray(num,0);
      for (let k in data){
        const day = data[k];
        xAxis.push(day.date);
        yUserNum.push(day.user_num);
        yIpNum.push(day.ip_num);
      }
      const option = {
        title: {
          text: '每日登陆数据'
        },
        tooltip: {},
        legend: {
          data: ['登陆人数','登陆IP数']
        },
        xAxis: {
          data: xAxis,
          type:'category'
        },
        yAxis: {},
        series: [
          {
            name: '登陆人数',
            type: 'line',
            data: yUserNum
          },{
            name: '登陆IP数',
            type: 'line',
            data: yIpNum
          }
        ]
      };


      if (option && typeof option === 'object') {
        getApp('container').setOption(option);
      }


    });
  </script>
</body>
</html>